<template>
  <div>
    <van-nav-bar fixed title="签到排名" left-arrow @click-left="$utils.back($route.path)" />
    <div class="has-top">
      <img src="@/assets/images/topbg.png" />
      <div class="mlr-24 mt--150 pos-r">
        <div class="flex tab">
          <div :class="current == 0 ? 'active' : ''" @click="tab(0)">
            <p>今日签到</p>
            <span v-show="current == 0"></span>
          </div>
          <div :class="current == 1 ? 'active' : ''" @click="tab(1)">
            <p>累计签到</p>
            <span v-show="current == 1"></span>
          </div>
        </div>
        <div class="bg-white pt-40 fs-28">
          <div class="flex-s-c my mlr-20 mb-40">
            <div class="flex-v-c">
              <span class="fs-24 grade">我的<br/>成绩</span>
              <div class="pos-r userimg mr-15">
                <img v-if="mySigndata.Position == 1" src="@/assets/images/crown1.png" class="crown" />
                <img v-if="mySigndata.Position == 2" src="@/assets/images/crown2.png" class="crown" />
                <img v-if="mySigndata.Position == 3" src="@/assets/images/crown3.png" class="crown" />
                <headPortrait-box class="img-box pos-r br-full is-72 headimg" :class="mySigndata.Position == 1 ? 'rankone': mySigndata.Position == 2 ? 'ranktwo' : mySigndata.Position == 3 ? 'rankthree' : ''" :headPortraitUrl="mySigndata.Images"></headPortrait-box>
              </div>
              <p class="fs-26 text-show-line-1 w200" :class="mySigndata.Position == 1? 'ranktext1': mySigndata.Position == 2? 'ranktext2': mySigndata.Position == 3? 'ranktext3': ''">{{ mySigndata.NickName }}</p>
              <div class="fw-500 pl-20" v-if="mySigndata.Position">第{{ mySigndata.Position }}名</div>
            </div>
            <time class="fw-b pr-16" v-if="current == 0 && mySigndata.SignInTime">{{
              mySigndata.SignInTime.substring(mySigndata.SignInTime.length - 3, mySigndata.SignInTime.length - 8)
            }}</time>
             <time class="fs-24 pr-16" v-if="current == 0 && !mySigndata.SignInTime">暂未打卡</time>
            <time class="fs-24 pr-16" v-if="current == 1"
              >已签到<span class="fs-28 fw-b" style="color:#f7762c">{{ mySigndata.Total }}</span
              >天</time>
          </div>
          <div class="clock fw-500 color-white flex-center" @click="$router.push('/fission')">立即打卡</div>
          <div class="fs-24 flex-s-c pl-32 pr-40" style="color:#999">
            <div class="flex-v-c">
              <p class="pr-60">排名</p>
              <p>姓名</p>
            </div>
            <div>{{current == 0?'签到时间':'签到天数'}}</div>
          </div>
          <template  v-if="list.length !== 0">
          <div class="flex-s-c fs-28 plr-40 ptb-25" v-for="(item,index) in list" :key="index">
            <div class="flex-v-c">
              <span class="rank" :class="item.Position == 1? 'ranktext1': item.Position == 2? 'ranktext2': item.Position == 3? 'ranktext3': ''">{{index+1}}</span>
              <div class="pos-r userimg mr-20 ml-50">
                <img v-if="item.Position == 1" src="@/assets/images/crown1.png" class="crown" />
                <img v-if="item.Position == 2" src="@/assets/images/crown2.png" class="crown" />
                <img v-if="item.Position == 3" src="@/assets/images/crown3.png" class="crown" />
                <headPortrait-box class="img-box pos-r br-full is-72 headimg" :class="item.Position == 1 ? 'rankone': item.Position == 2 ? 'ranktwo' : item.Position == 3 ? 'rankthree' : ''" :headPortraitUrl="item.Images"></headPortrait-box>
              </div>
              <p class="fs-26 text-show-line-1 w300" :class="item.Position == 1? 'ranktext1': item.Position == 2? 'ranktext2': item.Position == 3? 'ranktext3': ''">{{ item.NickName }}</p>
            </div>
            <div class="fw-b" v-if="current==0 && item.SignInTime">{{item.SignInTime.substring(item.SignInTime.length - 3, item.SignInTime.length - 8)}}</div>
            <div class="fs-24" v-if="current==1">已签到<span class="fs-28" style="color:#f7762c">{{item.Total}}</span>天</div>
          </div>
          </template>
          <no-data v-else/>
          <p v-show="end === true && list.length !== 0" class="tac fs-36 ptb-20">无更多数据</p>
          
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import noData from 'components/noData'
import headPortraitBox from 'components/headPortraitBox'
import { GetPosterSignInInfo, GetPosterSignInRankingList } from 'api/poster'
export default {
  components: {
    noData,
    headPortraitBox
  },
  data() {
    return {
      mySigndata: {}, //我的成绩
      datalist: [],
      list: [], //列表数据
      current: 0,
      requestData: {
        posterSignInInfoType: 0,
        PageIndex: 1,
        PageSize: 20
      },
      // 滚动状态
      totalAmout: 0,
      scollRequest: true,
      end: false
    }
  },
  computed: {},
  created() {
    this.GetPosterSignInInfo()
    this.GetPosterSignInRankingList()
  },
  methods: {
    tab(num) {
      if (this.current != num) {
        this.current = num
        this._resetList()
      }
    },
    _resetList(){
      this.$nextTick(function(){
        this.requestData.PageIndex = 1;
        this.totalAmout = 0
        this.scollRequest = true
        this.end = false
        this.list = [];
        this.datalist = [];
        this.GetPosterSignInInfo()
        this.GetPosterSignInRankingList()
      });
  
    },
    GetPosterSignInInfo() {
      GetPosterSignInInfo({ posterSignInInfoType: this.current }).then(res => {
        if (res) {
          this.mySigndata = res.Data
        }
      })
    },
    GetPosterSignInRankingList() {
      this.requestData.posterSignInInfoType = this.current;
      GetPosterSignInRankingList(this.requestData).then(res => {
        if (res && res.Data && res.Data.length > 0) {
          this.datalist = this.datalist.concat(res.Data);
          console.log(this.datalist)
          var list = this.datalist;
          this.list = list;
          this.totalAmout = res.TotalAmout
          this.scollRequest = true
        }
      })
    },
    // 滚动事件触发下拉加载
    onScroll() {
      const _this = this
      if (_this.scollRequest === true) {
        if (_this.$utils.getScrollHeight() - _this.$utils.getClientHeight() - _this.$utils.getScrollTop() <= 5) {
          _this.scollRequest = false
          if (_this.requestData.PageIndex < _this.totalAmout) {
            _this.requestData.PageIndex++
            _this.GetPosterSignInRankingList()
          } else {
            _this.end = true

          }
          // }
        }
      }
    }
  },
  mounted() {
    this.$nextTick(function() {
      window.addEventListener('scroll', this.onScroll)
    })
  }
}
</script>
<style lang="scss" scoped>
.tab {
  align-items: baseline;
  & > div {
    width: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 80px;
    font-size: 28px;
    font-weight: 400;
    position: relative;
    background: rgba($color: #ffffff, $alpha: 0.7);
    // position: relative;
    bottom: -4px;
    &:first-child {
      // border-bottom-right-radius:16px;
      border-top-left-radius: 16px;
    }
    &:last-child {
      // border-bottom-left-radius:16px;
      border-top-right-radius: 16px;
    }
  }
  & > div.active {
    bottom: 0px;
    height: 90px;
    background: #ffffff;
    color: #f7762c;
    font-size: 32px;
    font-weight: 500;
    border-top-right-radius: 16px;
    border-top-left-radius: 16px;
  }
  span {
    width: 42px;
    height: 6px;
    background: #f7762c;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    bottom: 14px;
    margin-left: -21px;
  }
}
.my {
  width: 662px;
  height: 142px;
  border-radius: 10px;
  box-shadow: 0px 0px 5px #f6f6f6;
  border: 1px solid #f6f6f6;
  color: #f7762c;
  .grade {
    width: 52px;
    height: 52px;
    line-height: 1.2;
    white-space: nowrap;
    margin: 0 24px 0 28px;
  }
  img.mr-15 {
    width: 72px;
    height: 72px;
    border: 1px solid #fff;
    border-radius: 50%;
  }
  .w200 {
    width: 200px;
  }
}
.clock {
  width: 224px;
  height: 84px;
  background: linear-gradient(125deg, #ffb57a, #fe9d6e);
  border: 2px solid #ffffff;
  box-shadow: 0px 4px 16px 0px rgba(4, 0, 0, 0.1);
  border-radius: 42px;
  margin: 0 auto 40px auto;
}
.userimg {
  width: 72px;
  height: 72px;
  .crown {
    width: 43px;
    height: 41px;
    position: absolute;
    top: -15px;
    left: -8px;
  }
  .headimg {
    border: 1px solid transparent;
  }
  .rankone {
    border: 1px solid #fe483a;
  }
  .ranktwo {
    border: 1px solid #fcc832;
  }
  .rankthree {
    border: 1px solid #5d85ff;
  }
}
.ranktext1 {
  color: #fe483a;
}
.ranktext2 {
  color: #fcc832;
}
.ranktext3 {
  color: #5d85ff;
}
.rank {
  width: 40px;
  text-align: left;
}
.w300 {
  width: 300px;
}
</style>
